package com.inno.oss.controller;

import com.inno.oss.entity.FileUploadDTO;
import com.inno.oss.error.OssException;
import com.inno.oss.response.CommonReturnType;
import com.inno.oss.service.OssService;
import com.inno.oss.utils.OssUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.net.MalformedURLException;

@Slf4j
@RestController
@RequestMapping("/oss")
public class OssController {
    @Autowired
    private OssService ossService;
    @PostMapping("/upload")
    public CommonReturnType<String> upload(@RequestParam("file") MultipartFile file) {
        try {
            String fileUrl = ossService.upload(file);
            return CommonReturnType.success(fileUrl);
        }catch (OssException oe){
            log.error("上传文件失败，原因：", oe);
            return CommonReturnType.fail(oe.getMessage());
        }


    }
}
